package znbkTestPaperXtfx.presenter;

import android.util.Log;

import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkListXtfx.ISystemReviewPresenter;
import znbkTestPaperXtfx.activity.SystemReviewPaperActivity;
import znbkTestPaperXtfx.api.SystemReviewPaperApi;
import znbkTestPaperXtfx.entity.SystemReviewPaperEntity;

/**
 * Created by Administrator on 2018\3\23 0023.
 */

public class SystemReviewPaperPresenter implements ISystemReviewPresenter {

    private ILoadPaperView view;

    public SystemReviewPaperPresenter(ILoadPaperView view) {
        this.view = (ILoadPaperView) view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();

        HttpOnNextListener<SystemReviewPaperEntity> httpOnNextListener = new HttpOnNextListener<SystemReviewPaperEntity>() {
            @Override
            public void onNext(SystemReviewPaperEntity systemReviewPaperEntity) {

                if (systemReviewPaperEntity.getModelSinglePaperInfo() != null) {
                    view.hideLoading();
                    view.loadPaperData(systemReviewPaperEntity);
                }else {
                    view.showNoData("暂无内容");
                }
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        SystemReviewPaperApi api = new SystemReviewPaperApi(httpOnNextListener, (SystemReviewPaperActivity)view);

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }


}